Overview
DevolutionSync implements a clean MVC (Model-View-Controller) architecture that separates business logic, data access, and presentation layers. This pattern ensures maintainability, testability, and scalability.MVC Pattern Diagram
Directory Structure
Controllers Layer
Purpose
Controllers handle HTTP requests, coordinate between models and views, and contain application flow logic.Controller Base Structure
Controller Responsibilities
Request Handling
- Receive HTTP requests
- Parse GET/POST parameters
- Validate input data
- Handle file uploads
Business Logic
- Call model methods
- Process data
- Apply business rules
- Handle transactions
Security
- Session management
- Authentication checks
- Authorization validation
- CSRF protection
Response
- Load views
- Return JSON
- Handle redirects
- Set headers
Controller Naming Convention
Pattern:
{Entity}Controller.php- Class name:
{Entity}Controller - File name:
{Entity}Controller.php - Location:
Controllers/ - Example:
AdminController.phpcontainsclass AdminController
Models Layer
Purpose
Models handle data access, database operations, and contain business logic related to data manipulation.Model Base Structure
Model Responsibilities
Data Access Layer
Data Access Layer
- Execute SQL queries
- Use prepared statements
- Handle database connections
- Return result sets
CRUD Operations
CRUD Operations
- Create: Insert new records
- Read: Query and fetch data
- Update: Modify existing records
- Delete: Remove records (soft/hard)
Business Logic
Business Logic
- Data validation
- Calculations and aggregations
- Transaction management
- Data transformations
Database Abstraction
Database Abstraction
- Hide SQL complexity
- Provide clean interfaces
- Return formatted data
- Handle database errors
PDO Connection Pattern
All models use theConexion class for database access:
The
Conexion::Conectar() method returns a configured PDO instance with:- Exception error mode
- Associative array fetch mode
- Real prepared statements (not emulated)
Prepared Statements
- With Positional Parameters
- With Named Parameters
Transaction Management
DevolucionModel.php (excerpt)
Views Layer
Purpose
Views handle presentation logic and render HTML templates with data provided by controllers.View Structure Example
Views/admin/panel_administrador.php (excerpt)
View Responsibilities
Presentation
- Render HTML
- Display data
- Format output
- Apply styling
User Interface
- Forms
- Tables
- Buttons
- Navigation
Data Display
- Loop through arrays
- Conditional rendering
- Format dates/numbers
- Escape output
Client-Side
- Include JavaScript
- Include CSS
- AJAX calls
- Event handlers
XSS Prevention
View Loading Pattern
Controllers load views usingrequire_once:
Variables defined in the controller method are automatically available in the required view file.
Data Flow Example
Complete Request-Response Cycle
Best Practices
Controller Best Practices
Keep Controllers Thin
Keep Controllers Thin
Controllers should orchestrate, not implement business logic:
Validate All Input
Validate All Input
Check Permissions Early
Check Permissions Early
Model Best Practices
Use Prepared Statements
Use Prepared Statements
Handle Transactions Properly
Handle Transactions Properly
Return Consistent Data Types
Return Consistent Data Types
View Best Practices
Always Escape Output
Always Escape Output
No Business Logic in Views
No Business Logic in Views
Separate Templates
Separate Templates
Testing Considerations
Unit Testing Models
Next Steps
Architecture Overview
Understand the complete system architecture
Database Schema
Explore the database structure
API Reference
View all controller and model methods
Deployment
Deploy with Docker